﻿package Common 
{
	import flash.display.InteractiveObject;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.system.ApplicationDomain;
	
	/**
	 * ...
	 * @author fox
	 */
	
	public class RenderManager 
	{
		public static var redraw:Boolean = true;

		
		public var stageWidth:int = 0;
		public var stageHeight:int = 0;
		
		private var root:Sprite = null;
		
		private var debug:Sprite = null;
		private var terrainSprite:Sprite = null;
		private var sceneSprite:Sprite = null;
		private var middleSprite:Sprite = null;
		private var uiSprite:Sprite = null;
		private var uiLoadingSprite:Sprite = null;
		private var loadingSprite:Sprite = null;
		
		public var stage:Stage = null;
		
		public function setFocus( obj:InteractiveObject ):void
		{
			stage.focus = obj;
		}
		
		public function RenderManager() 
		{
			
		}
		
		public function init( root:Sprite ):void
		{
			this.root = root;
			
			// terrain
			terrainSprite = new Sprite();
			terrainSprite.name = "terrain";
			terrainSprite.mouseEnabled = false;
			
			// scene
			sceneSprite = new Sprite();
			sceneSprite.name = "scene";
			sceneSprite.mouseEnabled = false;
			
			// middle
			middleSprite = new Sprite();
			middleSprite.name = "middle";
			middleSprite.mouseEnabled = false;
			
			// ui ,, 
			uiSprite = new Sprite();
			uiSprite.name = "ui";
			uiSprite.mouseEnabled = false;
			
			// ui loading ,, 
			uiLoadingSprite = new Sprite();
			uiLoadingSprite.name = "uiLoading";
			uiLoadingSprite.mouseEnabled = false;
			
			// loading
			loadingSprite = new Sprite();
			loadingSprite.name = "loading";
			loadingSprite.mouseEnabled = false;
			
			// debug,  
			debug = new Sprite();
			debug.name = "debug";
			debug.mouseChildren = false;
			debug.mouseEnabled = false;
			
			root.addChild( terrainSprite );
			root.addChild( sceneSprite );
			root.addChild( middleSprite );
			root.addChild( uiSprite );
			root.addChild( uiLoadingSprite );
			root.addChild( loadingSprite );
			root.addChild( debug );
		}
		
		
		public function get LoadingSprite():Sprite
		{
			return loadingSprite;
		}
		
		public function get SceneSprite():Sprite
		{
			return sceneSprite;
		}
		
		public function get MiddleSprite():Sprite
		{
			return middleSprite;
		}
		
		public function get UISprite():Sprite
		{
			return uiSprite;
		}
		
		public function get TerrainSprite():Sprite
		{
			return terrainSprite;
		}
		
		public function get UiLoadingSprite():Sprite
		{
			return uiLoadingSprite;
		}
		
		
		
		
		
		public function release():void
		{
			
		}
		
		
		public static var instance:RenderManager = null;
		public static function Instance():RenderManager
		{
			if ( instance == null )
			{
				instance = new RenderManager();
			}
			
			return instance;
		}
		
		public function get Debug():Sprite
		{
			return debug;
		}
		
//		public function get Root():Sprite
//		{
//			return root;
//		}
		

		
		
	}
	
}